package com.gym.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Date;

@Controller
public class UploadController {
    @RequestMapping(value = "/imgUpload", method = RequestMethod.POST)
    @ResponseBody
    public String uploadImg(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        Date date = new Date();
        long time = date.getTime();
        String filename = time + originalFilename;
//        将文件存放到nginx的文件夹路径
        file.transferTo(new File("D:\\imgUpload\\userImg\\" + filename));
        return filename;
    }

    @RequestMapping(value = "/courseImgUpload", method = RequestMethod.POST)
    @ResponseBody
    public String uploadCourseImg(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        Date date = new Date();
        long time = date.getTime();
        String filename = time + originalFilename;
//        将文件存放到nginx的文件夹路径
        file.transferTo(new File("D:\\imgUpload\\courseImg\\" + filename));
        return filename;
    }
}
